package com.erebus.submit.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


// 配置 CORS 头部
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        // 所有路径（/**）都允许跨域请求，允许的源为 http://localhost:17777，允许的方法包括 GET、POST、PUT、DELETE 和 OPTIONS，允许的请求头字段包括 Origin、X-Requested-With、Content-Type 和 Accept
        registry.addMapping("/**")
                .allowedOrigins("http://10.102.3.67:17777")
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
                .allowedHeaders("Origin", "X-Requested-With", "Content-Type", "Accept");
    }
}
